package com.ruoyi.web.controller.business;

import com.ruoyi.system.domain.ConfigDto;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Field;
import java.util.List;

/**
 * @author Larry
 * @date 2022/3/24 0024 13:32
 */
@RequestMapping("/shop/config")
@Api(tags = "配置")
@RestController
public class ConfigController {
    @Autowired
    private ISysConfigService configService;

    @PostMapping("/editShopConfig")
    @ApiOperation("配置项保存")
    public R editStartPageShopConfig(@RequestBody ConfigDto configStartPageDto) throws IllegalAccessException {
        configService.updateConfigByReflct(configStartPageDto);
        return R.ok();
    }

    @GetMapping("/getConfig")
    @ApiOperation("pcc/app单个配置项获取  userContract用户服务协议 buyContract 购买服务协议 aboutUs关于我们 ")
    public R<String> editStartPageShopConfig(String configName) throws IllegalAccessException {
        SysConfig config = configService.lambdaQuery().eq(SysConfig::getConfigKey, configName).one();
        return R.ok(config.getConfigValue());
    }



}
